
require(['./config'], () => {
require(['template','header','footer'],(template)=>{
    class List{
        constructor(){
            this.list()
            
            
        }
        list(){
            $.get('http://rap2.taobao.org:38080/app/mock/258670/api/list/shop',resp =>{
                
                this.resp = resp
                if (resp.code === 200) {
                    const { list } = resp.body
                    $('#shopList').html(template('shopTemplate', { list }))
                    this.orderUpBtn()
                    this.orderDownBtn()
                }
            })
        }
        orderUpBtn(){
            // console.log(this.resp)
            const { list } = this.resp.body
            $('.upBtn').on('click',function(){
                console.log(111)
               for(var i=0;i<list.length-1;i++){
                   for(var j =0;j<list.length-i-1;j++){
                       if(list[j].price>list[j+1].price){
                           var temp = list[j+1]
                           list[j+1]=list[j]
                           list[j]=temp
                       }
                   }
               }
               $('#shopList').html(template('shopTemplate', { list }))
                
                // console.log(list)
            })
        }
        orderDownBtn(){
            const { list } = this.resp.body
            $('.downBtn').on('click',function(){
                console.log(222)
               for(var i=0;i<list.length-1;i++){
                   for(var j =0;j<list.length-i-1;j++){
                       if(list[j].price<list[j+1].price){
                           var temp = list[j+1]
                           list[j+1]=list[j]
                           list[j]=temp
                       }
                   }
               }
               $('#shopList').html(template('shopTemplate', { list }))
                
                // console.log(list)
            })
        }
    }
    return new List()
})
})